﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Project_V1
{
    public partial class FrmHardwareConfig : Form
    {
        public FrmHardwareConfig()
        {
            InitializeComponent();
            this.Load += FrmHardwareConfig_Load;
        }

        //打开IO变量配置窗体
        void FrmHardwareConfig_Load(object sender, EventArgs e)
        {
            btn_ParaSetConfig_Click(null, null);
        }

        #region 打开窗体方法,和主界面的方法一样
        private void OpenWindow(Form Frm)
        {
            Frm.TopLevel = false;
            Frm.FormBorderStyle = FormBorderStyle.None;
            Frm.Dock = DockStyle.Fill;
            Frm.Parent = this.MainPanel;
            Frm.Show();
        }

        private bool CloseWindow(string FrmName)
        {
            foreach (Control ct in this.MainPanel.Controls)
            {
                if (ct is Form)
                {
                    Form Frm = (Form)ct;
                    if (Frm.Name == FrmName)
                    {
                        return true;
                    }
                    else
                    {
                        Frm.Close();
                    }
                }
            }
            return false;
        }
        #endregion 

        //打开IO变量配置窗体
        private void btn_IOVarManage_Click(object sender, EventArgs e)
        {
            if (CloseWindow("FrmIOVarManage") == false)
            {
                OpenWindow(new FrmIOVarManage());
            }
        }

        //打开协议信息配置窗体
        private void btn_ProtocolManage_Click(object sender, EventArgs e)
        {
            if (CloseWindow("FrmSysSetings") == false)
            {
                OpenWindow(new FrmSysSetings());
            }
        }

        //打开参数配置窗体
        private void btn_ParaSetConfig_Click(object sender, EventArgs e)
        {
            if (CloseWindow("FrmParamSet") == false)
            {
                OpenWindow(new FrmParamSet());
            }
        }

        //打开趋势图参数配置窗体
        private void btn_TrendParaConfig_Click(object sender, EventArgs e)
        {
           
        }
    }
}
